package com.eos.control.action.activity;

import com.eos.business.service.SysActivityBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysActivty;
import com.eos.orm.mybatis.model.SysActivtySon;
import com.eos.orm.mybatis.model.SysUser;

public class SaveSonActivityAction extends AbstractBaseAction {
	private static final long serialVersionUID = 5818969115166973870L;
	private String activtySonName;
	private String activtySonDesc;
	private Integer activtyId;

	public void setActivtySonName(String activtySonName) {
		this.activtySonName = activtySonName;
	}

	public void setActivtySonDesc(String activtySonDesc) {
		this.activtySonDesc = activtySonDesc;
	}

	public void setActivtyId(Integer activtyId) {
		this.activtyId = activtyId;
	}

	@Override
	public String execute() {
		try {
			String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
			SysUser user = (SysUser) getSession().getAttribute("SysUser");
			String userId = user.getId()+"";
			SysActivtySon sas = new SysActivtySon();
			sas.setActivtyId(activtyId);
			sas.setActivtySonDesc(activtySonDesc);
			sas.setActivtySonName(activtySonName);
			sas.setDealFlag(ConstantTool.DEAL_FALG_OK);
			sas.setInsertTime(strTime);
			sas.setInsertUserId(userId);
			sas.setModifyTime(strTime);
			sas.setRelationConfig("0");
			sas.setStatus(ConstantTool.STATUS_OK);
			sas.setUpdateUserId(userId);
			 
			SysActivityBusinessService sabs = new SysActivityBusinessService();
			String exeStatus = sabs.saveSonActivity(sas);
			if ("SUCCESS".equals(exeStatus)) {
				statusCode = "200";
				message = "保存子活动信息成功!";
				
				SysActivty sa = sabs.getSysActivityPrimaryKey(activtyId);
				Integer num = sa.getActivtySon();
				int sum = (null==num || num.intValue()==0)  ? 1 : (num + 1);
				
				SysActivty newSa = new SysActivty();
				newSa.setId(activtyId);
				newSa.setActivtySon(sum);
				sabs.updateSysActivtyPKSelective(newSa);
			} else {
				statusCode = "300";
				message = "系统繁忙, 保存子活动信息失败!";
			}
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常,保存子活动信息失败!";
		}
		return SUCCESS;
	}
}
